package com.metadata_system.ai.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.metadata_system.common.db.entity.Metadata;
import com.metadata_system.common.db.entity.MetadataView;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
public class MetadataViewResponse {
    private Integer id;
    private Integer metadataId;
    private String name;
    private String shortName;
    private Integer nodeTotal;
    private Integer edgeTotal;
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createdTime;
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updatedTime;

    public static MetadataViewResponse fromEntity(MetadataView metadataView){
        return MetadataViewResponse.builder()
                .id(metadataView.getId())
                .metadataId(metadataView.getMetadataId())
                .name(metadataView.getName())
                .nodeTotal(metadataView.getNodeTotal())
                .edgeTotal(metadataView.getEdgeTotal())
                .shortName(metadataView.getShortName())
                .createdTime(metadataView.getCreatedTime())
                .updatedTime(metadataView.getUpdatedTime())
                .build();
    }

    public static List<MetadataViewResponse> fromEntity(List<MetadataView> list){
        return list.stream().map(MetadataViewResponse::fromEntity).collect(Collectors.toList());
    }
}
